import turtle
import random
import math

# 设置画布
screen = turtle.Screen()
screen.title("五彩五角星")
screen.bgcolor("black")  # 黑色背景，让星星更显眼

# 创建画笔
pen = turtle.Turtle()
pen.speed(0)  # 最快速度
pen.hideturtle()  # 隐藏画笔

# 定义五角星颜色列表
colors = ["red", "orange", "yellow", "green", "blue", "purple", "pink", "cyan", "white"]

def draw_star(t, size):
    """绘制一个五角星"""
    t.begin_fill()
    for _ in range(5):
        t.forward(size)
        t.right(144)  # 五角星的角度
    t.end_fill()

# 绘制多个五角星
num_stars = 30  # 星星数量
for _ in range(num_stars):
    # 随机选择颜色
    color = random.choice(colors)
    pen.color(color)
    
    # 随机位置
    x = random.randint(-300, 300)
    y = random.randint(-200, 200)
    
    # 随机大小
    size = random.randint(10, 50)
    
    # 移动到指定位置
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    
    # 绘制五角星
    draw_star(pen, size)

# 点击关闭窗口
screen.exitonclick()
